package com.student.liu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.student.liu.entity.UserReceiveraddress;
import com.student.liu.mapper.IUserReceiveraddressMapper;
import com.student.liu.service.IUserReceiveraddressService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 用户收货地址服务接口实现类
 */
@Service
public class UserReceiveraddressServiceImpl extends ServiceImpl<IUserReceiveraddressMapper, UserReceiveraddress>
        implements IUserReceiveraddressService {


    @Override
    public void address(UserReceiveraddress userReceiveraddress) {
        save(userReceiveraddress);
    }

    @Override
    public IPage<Map<String, Object>> addressPage(Integer pageIndex, Integer pageSize) {
        Integer userId = Integer.parseInt(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        Page page = new Page(pageIndex, pageSize);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        return pageMaps(page,queryWrapper);
    }

    @Override
    public void remove(Integer id) {
        removeById(id);
    }
}
